import { useUserStore} from "../store/user";
import constants from "../utils/constants";
const userStore = useUserStore()
const header = {
    'Content-Type': 'application/json',
    'authentication': userStore.getUserToken
  }

export function getGroupDetail(id){
    return new Promise((resolve, reject) => {
        wx.request({
            url:constants.database + `/user/category/detail/${id}`,
            method:'GET',
            header: header,
            success: (res) => {
                resolve(res); // 返回原始 res 对象
            },
            fail: (err) => {
                reject(err);
            }
        })
      });
}

export function getAlarmList(){
    return new Promise((resolve,reject) => {

        wx.request({
            url:constants.database + '/user/alarm/list',
            method:'GET',
            header:header,
            success:(res) => {
                resolve(res)
            }
        })
    })
}

export function addNewAlarm(time,interval){
    wx.request({
        url:constants.database + '/user/alarm/add',
        method:'POST',
        header:header,
        data:{
            alarmTime:time,
            interval:interval,
            status:0
        }
    })
    
}

export function addTimeGroup(id,groupId){
console.log(id + '+' + groupId);


    wx.request({
        url:constants.database + '/user/alarm/clocks/connection',
        method:'POST',
        data:{
            alarmId:id,
            categoryId:groupId
        },
        header:header
    })
}

export function getAllGroupAlarm(){
    return new Promise((resolve) =>{
        wx.request({
            url:constants.database + '/user/alarm/showList',
            method:'GET',
            header:header,
            success:(res)=>{
                resolve(res)
            }
        })
    })
}

export function deleteTime(id){
    console.log(3);
    wx.request({
        url:constants.database + `/user/alarm/delete/${id}`,
        method:'DELETE',
        header:header
    })
}

export function deleteGroupAlarm(alarmId,categoryId){
    wx.request({
      url:constants.database + `/user/alarm/clocks/disConnection`,
      method:'PUT',
      data:{
        alarmId:alarmId,
        categoryId:categoryId
      },
      header:header
    })
}